﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="FishDetail.aspx.vb" Inherits="FishTank.FishDetail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <asp:FormView ID="DetailFormView" runat="server" width="100%" CssClass="detailView">
            <EditItemTemplate>
                <h1>Edit fish species</h1>

                <span class="failureNotification">
                    <asp:Literal ID="FailureText" runat="server"></asp:Literal>
                </span>
                <asp:ValidationSummary ID="FishInfoValidationSummary" runat="server" CssClass="failureNotification" 
                     ValidationGroup="FishInfoValidationGroup"/>

                <div class="itemInfo">
                <fieldset class="item">
                    <legend>Fish Information</legend>
                    <p>
                        <asp:Label ID="TitleLabel" runat="server" AssociatedControlID="TitleTextBox">Common Name:</asp:Label>
                        <asp:TextBox ID="TitleTextBox" runat="server" CssClass="textEntry" Text='<%# Bind("Title") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="TitleRequiredValidator" runat="server" ControlToValidate="TitleTextBox" 
                             CssClass="failureNotification" ErrorMessage="Common name is required." ToolTip="Common name is required." 
                             ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="SciNameLabel" runat="server" AssociatedControlID="SciNameTextBox">Scientific Name:</asp:Label>
                        <asp:TextBox ID="SciNameTextBox" runat="server" CssClass="textEntry" Text='<%# Bind("ScientificName") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="SciNameRequiredValidator" runat="server" ControlToValidate="SciNameTextBox" 
                             CssClass="failureNotification" ErrorMessage="Scientific name is required." ToolTip="Scientific name is required." 
                             ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="DescriptionLabel" runat="server" AssociatedControlID="DescriptionTextBox">Description:</asp:Label>
                        <asp:TextBox ID="DescriptionTextBox" runat="server" CssClass="textEntry" TextMode="MultiLine"
                                     Text='<%# Bind("Description") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="DescRequiredFieldValidator" runat="server" ControlToValidate="DescriptionTextBox" 
                             CssClass="failureNotification" ErrorMessage="Fish description is required." ToolTip="Fish description is required." 
                             ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="DietLabel" runat="server" AssociatedControlID="DietTextBox">Diet habbits:</asp:Label>
                        <asp:TextBox ID="DietTextBox" runat="server" CssClass="textEntry" TextMode="MultiLine"
                                     Text='<%# Bind("Diet") %>'></asp:TextBox>
                    </p>
                    <p class="textBody">
                        Minimum Tank Length: 
                        <asp:TextBox ID="MinTankLengthTextBox" runat="server" Width="32" Text='<%# Bind("MinTankSize") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="MinTankLengthRequiredValidator" runat="server" ControlToValidate="MinTankLengthTextBox" 
                            CssClass="failureNotification" ErrorMessage="Minimum Tank Length is required."
                            ToolTip="Minimum Tank Length is required." 
                            ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>cm
                        <asp:RangeValidator ID="MinTankLengthRangeValidator" runat="server" ControlToValidate="MinTankLengthTextBox" 
                            ErrorMessage="Tank Length minimum value is 1 and maximum is 1000" 
                            MinimumValue="1" MaximumValue="1000" Type="Double"
                            Display="None" ValidationGroup="FishInfoValidationGroup" ></asp:RangeValidator>
                        <asp:CompareValidator ID="LengthNumberValidator" runat="server" 
                            ControlToValidate="MinTankLengthTextBox" Display="None"
                            ErrorMessage="Min Tank Length is not an number"
                            Operator="DataTypeCheck" Type="Double"
                            ValidationGroup="FishInfoValidationGroup"></asp:CompareValidator>
                        &nbsp;

                        Maximum Fish Length:
                        <asp:TextBox ID="MaxFishLengthTextBox" runat="server" Width="32" Text='<%# Bind("MaxLength") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="MaxFishLengthRequiredValidator" runat="server" ControlToValidate="MaxFishLengthTextBox" 
                            CssClass="failureNotification" ErrorMessage="Max Fish Length is required." ToolTip="Max Fish Length is required." 
                            ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>cm
                        <asp:RangeValidator ID="MaxFishLengthRangeValidator" runat="server" ControlToValidate="MaxFishLengthTextBox" 
                            ErrorMessage="Fish Length minimum value is 1 and maximum is 100"
                            MinimumValue="1" MaximumValue="100" Type="Double"
                            Display="None" ValidationGroup="FishInfoValidationGroup"></asp:RangeValidator>
                        <asp:CompareValidator ID="MaxFishLengthNumberValidator" runat="server" 
                            ControlToValidate="MaxFishLengthTextBox" Display="None"
                            ErrorMessage="Max Fish Length is not a number"
                            Operator="DataTypeCheck" Type="Double"
                            ValidationGroup="FishInfoValidationGroup"></asp:CompareValidator>
                    </p>
                    <p class="textBody">
                        Water pH:
                        <asp:TextBox ID="phTextBox" runat="server" Width="32" Text='<%# Bind("pH") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="phRequiredValidator" runat="server" ControlToValidate="phTextBox" 
                            CssClass="failureNotification" ErrorMessage="pH is required." ToolTip="pH is required." 
                            ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="phRangeValidator" runat="server" ControlToValidate="phTextBox" 
                            ErrorMessage="pH minimum value is 0 and maximum is 14"
                            MinimumValue="0" MaximumValue="14" Type="Double"
                            Display="None" ValidationGroup="FishInfoValidationGroup"></asp:RangeValidator>
                        <asp:CompareValidator ID="phNumberValidator" runat="server" 
                            ControlToValidate="phTextBox" Display="None"
                            ErrorMessage="pH is not a number"
                            Operator="DataTypeCheck" Type="Double"
                            ValidationGroup="FishInfoValidationGroup"></asp:CompareValidator>
                        &nbsp;

                        Water Temperature:
                        <asp:TextBox ID="WaterTempTextBox" runat="server" Width="32" Text='<%# Bind("Temperature") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="WaterTempRequiredValidator" runat="server" ControlToValidate="WaterTempTextBox" 
                            CssClass="failureNotification" ErrorMessage="Water Temperature is required." ToolTip="Water Temperature is required." 
                            ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>°C
                        <asp:RangeValidator ID="WaterTempRangeValidator" runat="server" ControlToValidate="WaterTempTextBox" 
                            ErrorMessage="Water Temperature minimum value is 16°C and maximum is 36°C"
                            MinimumValue="16" MaximumValue="36" Type="Double"
                            Display="None" ValidationGroup="FishInfoValidationGroup"></asp:RangeValidator>
                        <asp:CompareValidator ID="WaterTempCompareValidator" runat="server" 
                            ControlToValidate="WaterTempTextBox" Display="None"
                            ErrorMessage="Water Temperature is not an number"
                            Operator="DataTypeCheck" Type="Double"
                            ValidationGroup="FishInfoValidationGroup"></asp:CompareValidator>
                    </p>
                    <p>
                        <asp:Label ID="PhotoLabel" runat="server" AssociatedControlID="PhotoFileUpload">Upload a Photo:</asp:Label>
                        <asp:FileUpload ID="PhotoFileUpload" runat="server" CssClass="fileUpload" />
                        <asp:RegularExpressionValidator ID="FileExtValidator" runat="server"
                            ValidationExpression="(.*\.([gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG]|[pP][nN][gG])$)"  
                            ControlToValidate="PhotoFileUpload" ErrorMessage="Only jpg/gif/png photos are supported."
                            ValidationGroup="FishInfoValidationGroup" Display="None"></asp:RegularExpressionValidator>
                    </p>
                    <p>
                        <asp:Label ID="CurrentPhotoLabel" runat="server" AssociatedControlID="PhotoFileUpload">Current Photo:</asp:Label>
                        <asp:Image ID="PhotoImage" runat="server"
                               ImageUrl='<%# GetPhotoNormalPath(CULng(Eval("PhotoID"))) %>'
                               AlternateText="<%# Bind('Title') %>"
                               CssClass="centered" />
                    </p>
                </fieldset>
                <p class="submitButton">
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" 
                        ValidationGroup="FishInfoValidationGroup" CausesValidation="False"
                        onclick="CancelEditButton_Click"/>
                    <asp:Button ID="SaveButton" runat="server" CommandName="Save" Text="Save" 
                        ValidationGroup="FishInfoValidationGroup" onclick="SaveButton_Click"/>
                </p>
                </div>
            </EditItemTemplate>
            <InsertItemTemplate>
                <h1>Add a fish species</h1>

                <span class="failureNotification">
                    <asp:Literal ID="FailureText" runat="server"></asp:Literal>
                </span>
                <asp:ValidationSummary ID="FishInfoValidationSummary" runat="server" CssClass="failureNotification" 
                     ValidationGroup="FishInfoValidationGroup"/>

                <div class="itemInfo">
                <fieldset class="item">
                    <legend>Fish Information</legend>
                    <p>
                        <asp:Label ID="TitleLabel" runat="server" AssociatedControlID="TitleTextBox">Common Name:</asp:Label>
                        <asp:TextBox ID="TitleTextBox" runat="server" CssClass="textEntry" Text=""></asp:TextBox>
                        <asp:RequiredFieldValidator ID="TitleRequiredValidator" runat="server" ControlToValidate="TitleTextBox" 
                             CssClass="failureNotification" ErrorMessage="Common name is required." ToolTip="Common name is required." 
                             ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="SciNameLabel" runat="server" AssociatedControlID="SciNameTextBox">Scientific Name:</asp:Label>
                        <asp:TextBox ID="SciNameTextBox" runat="server" CssClass="textEntry" Text=""></asp:TextBox>
                        <asp:RequiredFieldValidator ID="SciNameRequiredValidator" runat="server" ControlToValidate="SciNameTextBox" 
                             CssClass="failureNotification" ErrorMessage="Scientific name is required." ToolTip="Scientific name is required." 
                             ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="DescriptionLabel" runat="server" AssociatedControlID="DescriptionTextBox">Description:</asp:Label>
                        <asp:TextBox ID="DescriptionTextBox" runat="server" CssClass="textEntry" TextMode="MultiLine"
                                     Text=""></asp:TextBox>
                        <asp:RequiredFieldValidator ID="DescRequiredFieldValidator" runat="server" ControlToValidate="DescriptionTextBox" 
                             CssClass="failureNotification" ErrorMessage="Fish description is required." ToolTip="Fish description is required." 
                             ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="DietLabel" runat="server" AssociatedControlID="DietTextBox">Diet habbits:</asp:Label>
                        <asp:TextBox ID="DietTextBox" runat="server" CssClass="textEntry" TextMode="MultiLine"
                                     Text=""></asp:TextBox>
                    </p>
                    <p class="textBody">
                        Minimum Tank Length: 
                        <asp:TextBox ID="MinTankLengthTextBox" runat="server" Width="32"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="MinTankLengthRequiredValidator" runat="server" ControlToValidate="MinTankLengthTextBox" 
                            CssClass="failureNotification" ErrorMessage="Minimum Tank Length is required."
                            ToolTip="Minimum Tank Length is required." 
                            ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>cm
                        <asp:RangeValidator ID="MinTankLengthRangeValidator" runat="server" ControlToValidate="MinTankLengthTextBox" 
                            ErrorMessage="Tank Length minimum value is 1 and maximum is 1000" 
                            MinimumValue="1" MaximumValue="1000" Type="Double"
                            Display="None" ValidationGroup="FishInfoValidationGroup" ></asp:RangeValidator>
                        <asp:CompareValidator ID="LengthNumberValidator" runat="server" 
                            ControlToValidate="MinTankLengthTextBox" Display="None"
                            ErrorMessage="Min Tank Length is not an number"
                            Operator="DataTypeCheck" Type="Double"
                            ValidationGroup="FishInfoValidationGroup"></asp:CompareValidator>
                        &nbsp;

                        Maximum Fish Length:
                        <asp:TextBox ID="MaxFishLengthTextBox" runat="server" Width="32"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="MaxFishLengthRequiredValidator" runat="server" ControlToValidate="MaxFishLengthTextBox" 
                            CssClass="failureNotification" ErrorMessage="Max Fish Length is required." ToolTip="Max Fish Length is required." 
                            ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>cm
                        <asp:RangeValidator ID="MaxFishLengthRangeValidator" runat="server" ControlToValidate="MaxFishLengthTextBox" 
                            ErrorMessage="Fish Length minimum value is 1 and maximum is 100"
                            MinimumValue="1" MaximumValue="100" Type="Double"
                            Display="None" ValidationGroup="FishInfoValidationGroup"></asp:RangeValidator>
                        <asp:CompareValidator ID="MaxFishLengthNumberValidator" runat="server" 
                            ControlToValidate="MaxFishLengthTextBox" Display="None"
                            ErrorMessage="Max Fish Length is not a number"
                            Operator="DataTypeCheck" Type="Double"
                            ValidationGroup="FishInfoValidationGroup"></asp:CompareValidator>
                    </p>
                    <p class="textBody">
                        Water pH:
                        <asp:TextBox ID="phTextBox" runat="server" Width="32"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="phRequiredValidator" runat="server" ControlToValidate="phTextBox" 
                            CssClass="failureNotification" ErrorMessage="pH is required." ToolTip="pH is required." 
                            ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="phRangeValidator" runat="server" ControlToValidate="phTextBox" 
                            ErrorMessage="pH minimum value is 0 and maximum is 14"
                            MinimumValue="0" MaximumValue="14" Type="Double"
                            Display="None" ValidationGroup="FishInfoValidationGroup"></asp:RangeValidator>
                        <asp:CompareValidator ID="phNumberValidator" runat="server" 
                            ControlToValidate="phTextBox" Display="None"
                            ErrorMessage="pH is not a number"
                            Operator="DataTypeCheck" Type="Double"
                            ValidationGroup="FishInfoValidationGroup"></asp:CompareValidator>
                        &nbsp;

                        Water Temperature:
                        <asp:TextBox ID="WaterTempTextBox" runat="server" Width="32"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="WaterTempRequiredValidator" runat="server" ControlToValidate="WaterTempTextBox" 
                            CssClass="failureNotification" ErrorMessage="Water Temperature is required." ToolTip="Water Temperature is required." 
                            ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>°C
                        <asp:RangeValidator ID="WaterTempRangeValidator" runat="server" ControlToValidate="WaterTempTextBox" 
                            ErrorMessage="Water Temperature minimum value is 16°C and maximum is 36°C"
                            MinimumValue="16" MaximumValue="36" Type="Double"
                            Display="None" ValidationGroup="FishInfoValidationGroup"></asp:RangeValidator>
                        <asp:CompareValidator ID="WaterTempCompareValidator" runat="server" 
                            ControlToValidate="WaterTempTextBox" Display="None"
                            ErrorMessage="Water Temperature is not an number"
                            Operator="DataTypeCheck" Type="Double"
                            ValidationGroup="FishInfoValidationGroup"></asp:CompareValidator>
                    </p>
                    <p>
                        <asp:Label ID="PhotoLabel" runat="server" AssociatedControlID="PhotoFileUpload">Upload a Photo:</asp:Label>
                        <asp:FileUpload ID="PhotoFileUpload" runat="server" CssClass="fileUpload" />
                        <asp:RequiredFieldValidator ID="PhotoRequiredFieldValidator" runat="server" ControlToValidate="PhotoFileUpload" 
                             CssClass="failureNotification" ErrorMessage="Fish photo is required." ToolTip="Fish photo is required." 
                             ValidationGroup="FishInfoValidationGroup">*</asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="FileExtValidator" runat="server"
                            ValidationExpression="(.*\.([gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG]|[pP][nN][gG])$)"  
                            ControlToValidate="PhotoFileUpload" ErrorMessage="Only jpg/gif/png photos are supported."
                            ValidationGroup="FishInfoValidationGroup" Display="None"></asp:RegularExpressionValidator>
                    </p>
                </fieldset>
                <p class="submitButton">
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" 
                        ValidationGroup="FishInfoValidationGroup" CausesValidation="False"
                        PostBackUrl="~/Pages/FishList.aspx" />
                    <asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" 
                        ValidationGroup="FishInfoValidationGroup" onclick="SubmitButton_Click"/>
                </p>
                </div>
            </InsertItemTemplate>
            <ItemTemplate>
                <h1>
                    <asp:Label ID="TitleLabel" runat="server" Text="<%# Bind('Title') %>"></asp:Label>
                    (<asp:Label ID="Label1" runat="server" Text="<%# Bind('ScientificName') %>"></asp:Label>)
                </h1>

                <p class="author">
                    by
                    <a href="/Pages/MemberDetail.aspx?UserName=<%# Eval("MemberUserName") %>">
                        <asp:Label ID="MemberLabel" runat="server" Text='<%# Bind("MemberFullName") %>' />
                    </a>
                    at
                    <asp:Label ID="CreatedDateLabel" runat="server" Text='<%# Bind("CreatedDateTime", "{0:MMMM d, yyyy}") %>' />
                </p>

                <p class="textBody">
                    <asp:Image ID="PhotoImage" runat="server"
                               ImageUrl='<%# GetPhotoNormalPath(CULng(Eval("PhotoID"))) %>'
                               AlternateText="<%# Bind('Title') %>"
                               CssClass="centered" />
                </p>

                <dl>
                    <dt>Common Name</dt>
                        <dd><asp:Label ID="CommonNameLabel" runat="server" Text='<%# Bind("Title") %>' /></dd>
                    <dt>Scientific Name</dt>
                        <dd><asp:Label ID="ScientificNameLabel" runat="server" Text='<%# Bind("ScientificName") %>' /></dd>
                    <dt>Maximum Length</dt>
                        <dd><asp:Label ID="MaxLengthLabel" runat="server" Text='<%# Bind("MaxLength") %>' />cm</dd>
                    <dt>Minimum Tank Length</dt>
                        <dd><asp:Label ID="Label2" runat="server" Text='<%# Bind("MinTankSize") %>' />cm</dd>
                    <dt>Water Temperature</dt>
                        <dd><asp:Label ID="TemperatureLabel" runat="server" Text='<%# Bind("Temperature") %>' />°C</dd>
                    <dt>Water pH</dt>
                        <dd><asp:Label ID="phLabel" runat="server" Text='<%# Bind("pH") %>' /></dd>
                </dl>   

                <p class="textBody">
                    <asp:Label ID="DescriptionLabel" runat="server"
                        Text='<%# Convert.ToString(Eval("Description")).Replace(Environment.NewLine, "<br />") %>' />
                </p>

                <p class="textBody">
                    <asp:Label ID="DietLabel" runat="server"
                        Text='<%# Convert.ToString(Eval("Diet")).Replace(Environment.NewLine, "<br />") %>' />
                </p>
   
                <p class="submitButton">
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" 
                                onclick="DeleteButton_Click" Visible="<%# ModificationPermitted() %>"/>
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" 
                                onclick="EditButton_Click" Visible="<%# ModificationPermitted() %>"/>
                </p>
            </ItemTemplate>
        </asp:FormView>
</asp:Content>
